/*
class Base{
    int a;
    int b;

    public void methodA() {
        System.out.println("Base中的方法A被调用");
    }

    public void methodB() {
        System.out.println("Base中的方法B被调用");
    }
}

class Derived extends Base {
    //与父类中的变量同名且同类型
    int a;
    int b;

    //与父类中的methodA构成重载
    public void methodA() {
        System.out.println("Derived中的方法A被调用");
    }

    public void methodB() {
        System.out.println("Derived中的方法B被调用");
    }

    public int getSuperA() { return super.a; }
    public int getSuperB() { return super.b; }

    public void methodC() {
        a = 100;       // 子类的 a
        b = 101;       // 子类的 b
        super.a = 200; // 父类的 a
        super.b = 201; // 父类的 b
    }

}

public class Test {
    public static void main(String[] args) {
        Derived derived = new Derived();
        Base base = new Base();
        derived.methodC();
        int a = derived.a;
        int b = derived.b;
        int c = derived.getSuperA();
        int d = derived.getSuperB();
        System.out.println(a + " " + b +" " + c + " " + d);
    }
}
*/
/*
class Base {
    public Base(int a) {
        System.out.println("Base()");
    }
}

class Derived extends Base {
    public Derived() {
        super(10);
        System.out.println( "Derived()");
    }
}

public class Test {
    public static void main(String[] args) {
        Derived d  = new Derived();
    }
}

class Animal {
    String name;
    int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(name + "吃饭");
    }
}

 class cat extends Animal {
    public cat(String name, int age) {
        super(name, age);
    }

     @Override
     public void eat() {
         System.out.println(name + "吃鱼");
     }
 }

 class dog extends Animal {
     public dog(String name, int age) {
         super(name, age);
     }

     @Override
     public void eat() {
         System.out.println(name + "吃骨头");
     }
 }*/

class Animal {
    public void sound() { System.out.println("动物叫"); }
}
class Dog extends Animal {
    @Override
    public void sound() { System.out.println("汪汪"); }
    public void bark() { System.out.println("犬吠"); }
}

public class Test {
    public static void main(String[] args) {
        // 向上转型
        Animal animal = new Dog();  // 父类引用指向子类对象
        animal.sound();  // 输出：汪汪（动态绑定到子类方法）
// animal.bark();  // 编译错误：父类引用无法访问子类特有的方法
    }
}



